#include <dirent.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>

int main(int argc, char **argv)
{
    if (argc < 2)
    {
        printf("Usage: %s directory\n", argv[0]);
        return 1;
    }

    // 自动创建目录
    if (access(argv[1], F_OK) == -1)
    {
        mkdir(argv[1], 0755);
    }

    DIR *dir = opendir(argv[1]);
    struct dirent *entry;
    while ((entry = readdir(dir)) != NULL)
    {
        printf("%s\n", entry->d_name);
    }
    closedir(dir);
    return 0;
}